<?php
namespace BP\Sys;

use BP\En\EntityMyPK;

require_once("BP/En/Map.php");
require_once("BP/Tools/DateUtils.php");
require_once("BP/Web/WebUser.php");
class MapAttr extends EntityMyPK {
	public $_ens;	// EntitiesNoName
	protected $_dt;	// DataTable
	private function __init() { // default class members
		$this->_ens = NULL;
		$this->_dt = NULL;
	}
	public function getIsSupperText () 
	{
		return $this->GetParaBoolen(MapAttrAttr::$IsSupperText,  FALSE );
	}
	public function setIsSupperText ($value) // [boolean value]
	{
		$this->SetPara(MapAttrAttr::$IsSupperText, $value);
	}
	public function getIsRichText () 
	{
		return $this->GetParaBoolen(MapAttrAttr::$IsRichText,  FALSE );
	}
	public function setIsRichText ($value) // [boolean value]
	{
		$this->SetPara(MapAttrAttr::$IsRichText, $value);
	}
	public function getIsEnableQrCode () 
	{
		return $this->GetParaBoolen("IsEnableQrCode",  FALSE );
	}
	public function setIsEnableQrCode ($value) // [boolean value]
	{
		$this->SetPara("IsEnableQrCode", $value);
	}
	public function getIsSum () 
	{
		return $this->GetParaBoolen(MapAttrAttr::$IsSum,  TRUE );
	}
	public function setIsSum ($value) // [boolean value]
	{
		$this->SetPara(MapAttrAttr::$IsSum, $value);
	}
	public function getExtIsSum () 
	{
		return $this->GetParaBoolen(MapAttrAttr::$ExtIsSum,  TRUE );
	}
	public function setExtIsSum ($value) // [boolean value]
	{
		$this->SetPara(MapAttrAttr::$ExtIsSum, $value);
	}
	public function getUIIsInput () 
	{
		return $this->GetValBooleanByKey(MapAttrAttr::$UIIsInput,  FALSE );
	}
	public function setUIIsInput ($value) // [boolean value]
	{
		$this->SetValByKey(MapAttrAttr::$UIIsInput, $value);
	}
	public function getIsEnableInAPP () 
	{
		return $this->GetValBooleanByKey(MapAttrAttr::$IsEnableInAPP,  TRUE );
	}
	public function setIsEnableInAPP ($value) // [boolean value]
	{
		$this->SetValByKey(MapAttrAttr::$IsEnableInAPP, $value);
	}
	public function getIsEnableJS () 
	{
		return $this->GetParaBoolen("IsEnableJS",  FALSE );
	}
	public function setIsEnableJS ($value) // [boolean value]
	{
		$this->SetPara("IsEnableJS", $value);
	}
	public function getHisEntitiesNoName () 
	{
		if ($this->getUIBindKey()->contains("."))
		{
			$ens = $BP->En->ClassFactory->GetEns($this->getUIBindKey());
			if (($ens == NULL))
			{
				return NULL;
			}
			$ens->RetrieveAll();
			return $ens;
		}
		if (($this->_ens == NULL))
		{
			$sf = SFTable::constructor__String($this->getUIBindKey());
			if ($sf->getFK_SFDBSrc()->equals("local"))
			{
				$myens = new GENoNames($this->getUIBindKey(), $this->getName());
				if (($sf->getSrcType() == SrcType::$SQL))
				{
					$dt = $sf->GenerHisDataTable();
					$enn = NULL;
					foreach ($dt->Rows as $row) 					{
						$tempVar = $myens->getNewEntity();
						$enn = ( ($tempVar instanceof EntityNoName) ? $tempVar : NULL );
						$enn->setNo(( ($row->get("No") instanceof String) ? $row->get("No") : NULL ));
						$enn->setName(( ($row->get("Name") instanceof String) ? $row->get("Name") : NULL ));
						$myens->AddEntity($enn);
					}
				}
				else
				{
					$myens->RetrieveAll();
				}
				$this->_ens = $myens;
			}
			else
			{
				$myens = new GENoNames($this->getUIBindKey(), $this->getName());
				$this->_ens = $myens;
			}
		}
		return $this->_ens;
	}
	public function getHisDT () 
	{
		if (($this->_dt == NULL))
		{
			if ($DataType->IsNullOrEmpty($this->getUIBindKey()))
			{
				throw new \RuntimeException((("@属�?�：" . $this->getMyPK()) . " 丢失属�?? UIBindKey 字段�?"));
			}
			$sf = SFTable::constructor__String($this->getUIBindKey());
			$this->_dt = $sf->GenerHisDataTable();
		}
		return $this->_dt;
	}
	public function getIsTableAttr () 
	{
		return $DataType->IsNumStr($this->getKeyOfEn()->replace("F", ""));
	}
	public function getHisAttr () 
	{
		$attr = new Attr();
		$attr->setKey($this->getKeyOfEn());
		$attr->setDesc($this->getName());
		$s = $this->getDefValReal();
		if ($DataType->IsNullOrEmpty($s))
		{
			$attr->setDefaultValOfReal(NULL);
		}
		else
		{
			$attr->setDefaultValOfReal($this->getDefValReal());
		}
		$attr->setField($this->getField());
		$attr->setMaxLength($this->getMaxLen());
		$attr->setMinLength($this->getMinLen());
		$attr->setUIBindKey($this->getUIBindKey());
		$attr->UIIsLine = $this->getUIIsLine();
		$attr->setUIHeight(0);
		if (($this->getUIHeight() > 30))
		{
			$attr->setUIHeight($this->getUIHeight());
		}
		$attr->setUIWidth($this->getUIWidth());
		$attr->setMyDataType($this->getMyDataType());
		$attr->setUIRefKeyValue($this->getUIRefKey());
		$attr->setUIRefKeyText($this->getUIRefKeyText());
		$attr->setUIVisible($this->getUIVisible());
		$attr->setMyFieldType($FieldType->Normal);
		if ($this->getIsPK())
		{
			$attr->setMyFieldType($FieldType->PK);
		}
		switch ($this->getLGType()) {
			case $Enum:
				$attr->setUIContralType($this->getUIContralType());
				$attr->setMyFieldType($FieldType->Enum);
				$attr->setUIIsReadonly($this->getUIIsEnable());
				break;
			case $FK:
				$attr->setUIContralType($this->getUIContralType());
				$attr->setMyFieldType($FieldType->FK);
				$attr->setUIIsReadonly($this->getUIIsEnable());
				break;
			default:
				if ($this->getIsPK())
				{
					$attr->setMyFieldType($FieldType->PK);
				}
				$attr->setUIIsReadonly(!$this->getUIIsEnable());
				switch ($this->getMyDataType()) {
					case $DataType->AppBoolean:
						$attr->setUIContralType($UIContralType->CheckBok);
						$attr->setUIIsReadonly($this->getUIIsEnable());
						break;
					case $DataType->AppDate:
						if ($this->getTag()->equals("1"))
						{
							$attr->setDefaultVal($DataType->getCurrentDate());
						}
						break;
					case $DataType->AppDateTime:
						if ($this->getTag()->equals("1"))
						{
							$attr->setDefaultVal($DataType->getCurrentDate());
						}
						break;
					default:
						$attr->setUIContralType($this->getUIContralType());
						break;
				}
				break;
		}
		return $attr;
	}
	public function getIsPK () 
	{
		switch ($this->getKeyOfEn()) {
			case "OID":
			case "No":
			case "MyPK":
				return  TRUE ;
			default:
				return  FALSE ;
		}
	}
	public function getHisEditType () 
	{
		return $EditType->forValue($this->GetValIntByKey(MapAttrAttr::$EditType));
	}
	public function setHisEditType ($value) // [EditType value]
	{
		$this->SetValByKey(MapAttrAttr::$EditType, $value->getValue());
	}
	public function getFK_MapData () 
	{
		return $this->GetValStrByKey(MapAttrAttr::$FK_MapData);
	}
	public function setFK_MapData ($value) // [String value]
	{
		$this->SetValByKey(MapAttrAttr::$FK_MapData, $value);
	}
	public function getKeyOfEn () 
	{
		return $this->GetValStrByKey(MapAttrAttr::$KeyOfEn);
	}
	public function setKeyOfEn ($value) // [String value]
	{
		$this->SetValByKey(MapAttrAttr::$KeyOfEn, $value);
	}
	public function getLGType () 
	{
		return $FieldTypeS->forValue($this->GetValIntByKey(MapAttrAttr::$LGType));
	}
	public function setLGType ($value) // [FieldTypeS value]
	{
		$this->SetValByKey(MapAttrAttr::$LGType, $value->getValue());
	}
	public function getLGTypeT () 
	{
		return $this->GetValRefTextByKey(MapAttrAttr::$LGType);
	}
	public function getName () 
	{
		$s = $this->GetValStrByKey(MapAttrAttr::$Name);
		if ((($s . NULL) . $s->equals("")))
		{
			return $this->getKeyOfEn();
		}
		return $s;
	}
	public function setName ($value) // [String value]
	{
		$this->SetValByKey(MapAttrAttr::$Name, $value);
	}
	public function getIsNum () 
	{
		switch ($this->getMyDataType()) {
			caseDataType->AppString:
			caseDataType->AppDate:
			caseDataType->AppDateTime:
			caseDataType->AppBoolean:
				return  FALSE ;
			default:
				return  TRUE ;
		}
	}
	public function getDefValDecimal () 
	{
		return new BigDecimal($this->getDefVal());
	}
	public function getDefValReal () 
	{
		return $this->GetValStrByKey(MapAttrAttr::$DefVal);
	}
	public function setDefValReal ($value) // [String value]
	{
		$this->SetValByKey(MapAttrAttr::$DefVal, $value);
	}
	public function getColSpan () 
	{
		$i = $this->GetValIntByKey(MapAttrAttr::$ColSpan);
		if (($this->getUIIsLine() && ($i == 1)))
		{
			return 3;
		}
		if (($i == 0))
		{
			return 1;
		}
		return $i;
	}
	public function setColSpan ($value) // [int value]
	{
		$this->SetValByKey(MapAttrAttr::$ColSpan, $value);
	}
	public function getDefVal () 
	{
		$s = $this->GetValStrByKey(MapAttrAttr::$DefVal);
		if ($this->getIsNum())
		{
			if ($s->equals(""))
			{
				return "0";
			}
		}
		switch ($this->getMyDataType()) {
			caseDataType->AppDate:
				if (($this->getTag()->equals("1") || $s->equals("@RDT")))
					return $DataType->getCurrentDate();
				else
					return "          ";
			caseDataType->AppDateTime:
				if (($this->getTag()->equals("1") || $s->equals("@RDT")))
					return $DataType->getCurrentDataTime();
				else
					return "               ";
			default:
				break;
		}
		if (($s->contains("@") ==  FALSE ))
		{
			return $s;
		}
		switch ($s->toLowerCase()) {
			case "@WebUser.getNo()":
				return $WebUser->getNo();
			case "@WebUser.getName()":
				return $WebUser->getName();
			case "@WebUser.getFK_Dept()":
				return $WebUser->getFK_Dept();
			case "@WebUser.getFK_Dept()name":
				return $WebUser->getFK_DeptName();
			case "@WebUser.getFK_Dept()fullname":
				return $WebUser->getFK_DeptNameOfFull();
			case "@fk_ny":
				return $DataType->getCurrentYearMonth();
			case "@fk_nd":
				return $DataType->getCurrentYear();
			case "@fk_yf":
				return $DataType->getCurrentMonth();
			case "@rdt":
				if (($this->getMyDataType() == $DataType->AppDate))
				{
					return $DataType->getCurrentDate();
				}
				else
				{
					return $DataType->getCurrentDataTime();
				}
			case "@rd":
				if (($this->getMyDataType() == $DataType->AppDate))
				{
					return $DataType->getCurrentDate();
				}
				else
				{
					return $DataType->getCurrentDataTime();
				}
			case "@yyyy年MM月dd�?":
				return $DataType->getCurrentDataCNOfLong();
			case "@yyyy年MM月dd日hh时mm�?":
				return $DateUtils->format(new Date(), "yyyy年MM月dd日HH时mm�?");
			case "@yy年MM月dd�?":
				return $DataType->getCurrentDataCNOfShort();
			case "@yy年MM月dd日hh时mm�?":
				return $DateUtils->format(new Date(), "yy年MM月dd日HH时mm�?");
			default:
				return $s;
		}
	}
	public function setDefVal ($value) // [String value]
	{
		$this->SetValByKey(MapAttrAttr::$DefVal, $value);
	}
	public function getDefValOfBool () 
	{
		return $this->GetValBooleanByKey(MapAttrAttr::$DefVal,  FALSE );
	}
	public function setDefValOfBool ($value) // [boolean value]
	{
		$this->SetValByKey(MapAttrAttr::$DefVal, $value);
	}
	public function getField () 
	{
		return $this->getKeyOfEn();
	}
	public function getHisTBType () 
	{
		switch ($this->getMyDataType()) {
			caseDataType->AppMoney:
				return $BP->Web->Controls->TBType->Moneny;
			caseDataType->AppInt:
			caseDataType->AppFloat:
			caseDataType->AppDouble:
				return $BP->Web->Controls->TBType->Num;
			default:
				return $BP->Web->Controls->TBType->TB;
		}
	}
	public function getMyDataType () 
	{
		return $this->GetValIntByKey(MapAttrAttr::$MyDataType);
	}
	public function setMyDataType ($value) // [int value]
	{
		$this->SetValByKey(MapAttrAttr::$MyDataType, $value);
	}
	public function getMyDataTypeS () 
	{
		switch ($this->getMyDataType()) {
			case $DataType->AppString:
				return "String";
			case $DataType->AppInt:
				return "Int";
			case $DataType->AppFloat:
				return "Float";
			case $DataType->AppMoney:
				return "Money";
			case $DataType->AppDate:
				return "Date";
			case $DataType->AppDateTime:
				return "DateTime";
			case $DataType->AppBoolean:
				return "Bool";
			default:
				throw new \RuntimeException("没有判断�?");
		}
	}
	public function setMyDataTypeS ($value) // [String value]
	{
		switch ($value) {
			case "String":
				$this->SetValByKey(MapAttrAttr::$MyDataType, $DataType->AppString);
				break;
			case "Int":
				$this->SetValByKey(MapAttrAttr::$MyDataType, $DataType->AppInt);
				break;
			case "Float":
				$this->SetValByKey(MapAttrAttr::$MyDataType, $DataType->AppFloat);
				break;
			case "Money":
				$this->SetValByKey(MapAttrAttr::$MyDataType, $DataType->AppMoney);
				break;
			case "Date":
				$this->SetValByKey(MapAttrAttr::$MyDataType, $DataType->AppDate);
				break;
			case "DateTime":
				$this->SetValByKey(MapAttrAttr::$MyDataType, $DataType->AppDateTime);
				break;
			case "Bool":
				$this->SetValByKey(MapAttrAttr::$MyDataType, $DataType->AppBoolean);
				break;
			default:
				throw new \RuntimeException("sdsdsd");
		}
	}
	public function getMyDataTypeStr () 
	{
		return $DataType->GetDataTypeDese($this->getMyDataType());
	}
	public function getMaxLen () 
	{
		switch ($this->getMyDataType()) {
			case $DataType->AppDate:
				return 100;
			case $DataType->AppDateTime:
				return 100;
			default:
				break;
		}
		$i = $this->GetValIntByKey(MapAttrAttr::$MaxLen);
		if (($i > 4000))
		{
			$i = 4000;
		}
		if (($i == 0))
		{
			return 50;
		}
		return $i;
	}
	public function setMaxLen ($value) // [int value]
	{
		$this->SetValByKey(MapAttrAttr::$MaxLen, $value);
	}
	public function getMinLen () 
	{
		return $this->GetValIntByKey(MapAttrAttr::$MinLen);
	}
	public function setMinLen ($value) // [int value]
	{
		$this->SetValByKey(MapAttrAttr::$MinLen, $value);
	}
	public function getIsNull () 
	{
		if (($this->getMinLen() == 0))
		{
			return  FALSE ;
		}
		else
		{
			return  TRUE ;
		}
	}
	public function getGroupID () 
	{
		$str = $this->GetValStringByKey(MapAttrAttr::$GroupID);
		if (($str->equals("�?") || $str->equals("")))
		{
			return 0;
		}
		return $Long->parseLong($str);
	}
	public function setGroupID ($value) // [long value]
	{
		$this->SetValByKey(MapAttrAttr::$GroupID, $value);
	}
	public function getIsBigDoc () 
	{
		if ((($this->getUIRows() > 1) && ($this->getMyDataType() == $DataType->AppString)))
		{
			return  TRUE ;
		}
		return  FALSE ;
	}
	public function getUIRows () 
	{
		if (($this->getUIHeight() < 40))
			return 1;
		$d = new BigDecimal((new Float($this->getUIHeight())));
		$c = new BigDecimal(13);
		return $d->divide($c, 0, $RoundingMode->HALF_UP)->intValue();
	}
	public function getUIHeightInt () 
	{
		return $this->getUIHeight();
	}
	public function setUIHeightInt ($value) // [int value]
	{
		$this->SetValByKey(MapAttrAttr::$UIHeight, $value);
	}
	public function getUIHeight () 
	{
		return $this->GetValFloatByKey(MapAttrAttr::$UIHeight);
	}
	public function setUIHeight ($value) // [float value]
	{
		$this->SetValByKey(MapAttrAttr::$UIHeight, $value);
	}
	public function getUIWidthInt () 
	{
		return $this->getUIWidth();
	}
	public function setUIWidthInt ($value) // [int value]
	{
		$this->SetValByKey(MapAttrAttr::$UIWidth, $value);
	}
	public function getUIWidth () 
	{
		return $this->GetValFloatByKey(MapAttrAttr::$UIWidth);
	}
	public function setUIWidth ($value) // [float value]
	{
		$this->SetValByKey(MapAttrAttr::$UIWidth, $value);
	}
	public function getUIWidthOfLab () 
	{
		return 0;
	}
	public function getUIVisible () 
	{
		return $this->GetValBooleanByKey(MapAttrAttr::$UIVisible);
	}
	public function setUIVisible ($value) // [boolean value]
	{
		$this->SetValByKey(MapAttrAttr::$UIVisible, $value);
	}
	public function getUIIsEnable () 
	{
		return $this->GetValBooleanByKey(MapAttrAttr::$UIIsEnable);
	}
	public function setUIIsEnable ($value) // [boolean value]
	{
		$this->SetValByKey(MapAttrAttr::$UIIsEnable, $value);
	}
	public function getUIIsLine () 
	{
		return $this->GetValBooleanByKey(MapAttrAttr::$UIIsLine);
	}
	public function setUIIsLine ($value) // [boolean value]
	{
		$this->SetValByKey(MapAttrAttr::$UIIsLine, $value);
	}
	public function getIsSigan () 
	{
		if ($this->getUIIsEnable())
		{
			return  FALSE ;
		}
		return $this->GetValBooleanByKey(MapAttrAttr::$IsSigan);
	}
	public function setIsSigan ($value) // [boolean value]
	{
		$this->SetValByKey(MapAttrAttr::$IsSigan, $value);
	}
	public function getSignType () 
	{
		return SignType->forValue($this->GetValIntByKey(MapAttrAttr::$IsSigan));
	}
	public function setSignType ($value) // [SignType value]
	{
		$this->SetValByKey(MapAttrAttr::$IsSigan, $value->getValue());
	}
	public function getPara_FontSize () 
	{
		return $this->GetParaInt(MapAttrAttr::$FontSize);
	}
	public function setPara_FontSize ($value) // [int value]
	{
		$this->SetPara(MapAttrAttr::$FontSize, $value);
	}
	public function getRBShowModel () 
	{
		return $this->GetParaInt("RBShowModel");
	}
	public function setRBShowModel ($value) // [int value]
	{
		$this->SetPara("RBShowModel", $value);
	}
	public function getPara_Tip () 
	{
		return $this->GetParaString(MapAttrAttr::$Tip);
	}
	public function setPara_Tip ($value) // [String value]
	{
		$this->SetPara(MapAttrAttr::$Tip, $value);
	}
	public function getPara_SiganField () 
	{
		if ($this->getUIIsEnable())
		{
			return "";
		}
		return $this->GetParaString(MapAttrAttr::$SiganField);
	}
	public function setPara_SiganField ($value) // [String value]
	{
		$this->SetPara(MapAttrAttr::$SiganField, $value);
	}
	public function getPicType () 
	{
		if ($this->getUIIsEnable())
		{
			return PicType::$Auto;
		}
		return PicType->forValue($this->GetParaInt(MapAttrAttr::$PicType));
	}
	public function setPicType ($value) // [PicType value]
	{
		$this->SetPara(MapAttrAttr::$PicType, $value->getValue());
	}
	public function getTBModel () 
	{
		return TBModel->forValue($this->GetParaInt(MapAttrAttr::$TBModel));
	}
	public function setTBModel ($value) // [TBModel value]
	{
		$this->SetPara(MapAttrAttr::$TBModel, $value->getValue());
	}
	public function getUIBindKey () 
	{
		return $this->GetValStrByKey(MapAttrAttr::$UIBindKey);
	}
	public function setUIBindKey ($value) // [String value]
	{
		$this->SetValByKey(MapAttrAttr::$UIBindKey, $value);
	}
	public function getUIRefKey () 
	{
		$s = $this->GetValStrByKey(MapAttrAttr::$UIRefKey);
		if ((($s . NULL) . $s->equals("")))
		{
			$s = "No";
		}
		return $s;
	}
	public function setUIRefKey ($value) // [String value]
	{
		$this->SetValByKey(MapAttrAttr::$UIRefKey, $value);
	}
	public function getUIRefKeyText () 
	{
		$s = $this->GetValStrByKey(MapAttrAttr::$UIRefKeyText);
		if ((($s . NULL) . $s->equals("")))
		{
			$s = "Name";
		}
		return $s;
	}
	public function setUIRefKeyText ($value) // [String value]
	{
		$this->SetValByKey(MapAttrAttr::$UIRefKeyText, $value);
	}
	public function getTag () 
	{
		return $this->GetValStrByKey(MapAttrAttr::$Tag);
	}
	public function setTag ($value) // [String value]
	{
		$this->SetValByKey(MapAttrAttr::$Tag, $value);
	}
	public function getUIContralType () 
	{
		return $UIContralType->forValue($this->GetValIntByKey(MapAttrAttr::$UIContralType));
	}
	public function setUIContralType ($value) // [UIContralType value]
	{
		$this->SetValByKey(MapAttrAttr::$UIContralType, $value->getValue());
	}
	public function getF_Desc () 
	{
		switch ($this->getMyDataType()) {
			case $DataType->AppString:
				if (($this->getUIVisible() ==  FALSE ))
				{
					return (((("长度" . $this->getMinLen()) . "-") . $this->getMaxLen()) . "不可�?");
				}
				else
				{
					return ((("长度" . $this->getMinLen()) . "-") . $this->getMaxLen());
				}
			case $DataType->AppDate:
			case $DataType->AppDateTime:
			case $DataType->AppInt:
			case $DataType->AppFloat:
			case $DataType->AppMoney:
				if (($this->getUIVisible() ==  FALSE ))
				{
					return "不可�?";
				}
				else
				{
					return "";
				}
			default:
				return "";
		}
	}
	public function getTabIdx () 
	{
		return $this->GetValIntByKey(MapAttrAttr::$TabIdx);
	}
	public function setTabIdx ($value) // [int value]
	{
		$this->SetValByKey(MapAttrAttr::$TabIdx, $value);
	}
	public function getIdx () 
	{
		return $this->GetValIntByKey(MapAttrAttr::$Idx);
	}
	public function setIdx ($value) // [int value]
	{
		$this->SetValByKey(MapAttrAttr::$Idx, $value);
	}
	public function getX () 
	{
		return $this->GetValFloatByKey(MapAttrAttr::$X);
	}
	public function setX ($value) // [float value]
	{
		$this->SetValByKey(MapAttrAttr::$X, $value);
	}
	public function getY () 
	{
		return $this->GetValFloatByKey(MapAttrAttr::$Y);
	}
	public function setY ($value) // [float value]
	{
		$this->SetValByKey(MapAttrAttr::$Y, $value);
	}
	public static function constructor__ () 
	{
		$me = new self();
		$me->__init();
		return $me;
	}
	public static function constructor__String ($mypk) // [String mypk]
	{
		$me = new self();
		$me->__init();
		$me->setMyPK($mypk);
		$me->Retrieve();
		return $me;
	}
	public static function constructor__String_String ($fk_mapdata, $key) // [String fk_mapdata, String key]
	{
		$me = new self();
		$me->__init();
		$me->setFK_MapData($fk_mapdata);
		$me->setKeyOfEn($key);
		$me->Retrieve(MapAttrAttr::$FK_MapData, $me->getFK_MapData(), MapAttrAttr::$KeyOfEn, $me->getKeyOfEn());
		return $me;
	}
	public function getTextColSpan () 
	{
		$i = $this->GetValIntByKey(MapAttrAttr::$TextColSpan);
		if (($this->getUIIsLine() && ($i == 1)))
		{
			return 3;
		}
		return $i;
	}
	public function getRowSpan () 
	{
		$i = $this->GetValIntByKey(MapAttrAttr::$RowSpan);
		if (($this->getUIIsLine() && ($i == 1)))
		{
			return 3;
		}
		return $i;
	}
	public function getEnMap () 
	{
		if (($this->get_enMap() != NULL))
		{
			return $this->get_enMap();
		}
		$map = new Map("Sys_MapAttr", "实体属�??");
		$map->Java_SetDepositaryOfEntity($Depositary->None);
		$map->Java_SetDepositaryOfMap($Depositary->Application);
		$map->Java_SetEnType($EnType->Sys);
		$map->AddMyPK();
		$map->AddTBString(MapAttrAttr::$FK_MapData, NULL, "实体标识",  TRUE ,  TRUE , 1, 100, 20);
		$map->AddTBString(MapAttrAttr::$KeyOfEn, NULL, "属�??",  TRUE ,  TRUE , 1, 200, 20);
		$map->AddTBString(MapAttrAttr::$Name, NULL, "描述",  TRUE ,  FALSE , 0, 200, 20);
		$map->AddTBString(MapAttrAttr::$DefVal, NULL, "默认�?",  FALSE ,  FALSE , 0, 400, 20);
		$map->AddTBInt(MapAttrAttr::$UIContralType, 0, "控件",  TRUE ,  FALSE );
		$map->AddTBInt(MapAttrAttr::$MyDataType, 1, "数据类型",  TRUE ,  FALSE );
		$map->AddDDLSysEnum(MapAttrAttr::$LGType, 0, "逻辑类型",  TRUE ,  FALSE , MapAttrAttr::$LGType, "@0=普�?�@1=枚举@2=外键@3=打开系统页面");
		$map->AddTBFloat(MapAttrAttr::$UIWidth, 100, "宽度",  TRUE ,  FALSE );
		$map->AddTBFloat(MapAttrAttr::$UIHeight, 23, "高度",  TRUE ,  FALSE );
		$map->AddTBInt(MapAttrAttr::$MinLen, 0, "�?小长�?",  TRUE ,  FALSE );
		$map->AddTBInt(MapAttrAttr::$MaxLen, 300, "�?大长�?",  TRUE ,  FALSE );
		$map->AddTBString(MapAttrAttr::$UIBindKey, NULL, "绑定的信�?",  TRUE ,  FALSE , 0, 100, 20);
		$map->AddTBString(MapAttrAttr::$UIRefKey, NULL, "绑定的Key",  TRUE ,  FALSE , 0, 30, 20);
		$map->AddTBString(MapAttrAttr::$UIRefKeyText, NULL, "绑定的Text",  TRUE ,  FALSE , 0, 30, 20);
		$map->AddTBInt(MapAttrAttr::$ExtIsSum, 0, "是否显示合计(对从表有�?)",  TRUE ,  TRUE );
		$map->AddTBInt(MapAttrAttr::$UIVisible, 1, "是否可见",  TRUE ,  TRUE );
		$map->AddTBInt(MapAttrAttr::$UIIsEnable, 1, "是否启用",  TRUE ,  TRUE );
		$map->AddTBInt(MapAttrAttr::$UIIsLine, 0, "是否单独栏显�?",  TRUE ,  TRUE );
		$map->AddTBInt(MapAttrAttr::$UIIsInput, 0, "是否必填字段",  TRUE ,  TRUE );
		$map->AddTBInt(MapAttrAttr::$IsRichText, 0, "富文�?",  TRUE ,  TRUE );
		$map->AddTBInt(MapAttrAttr::$IsSupperText, 0, "富文�?",  TRUE ,  TRUE );
		$map->AddTBInt(MapAttrAttr::$FontSize, 0, "富文�?",  TRUE ,  TRUE );
		$map->AddTBInt(MapAttrAttr::$IsSigan, 0, "签字�?",  TRUE ,  FALSE );
		$map->AddTBFloat(MapAttrAttr::$X, 5, "X",  TRUE ,  FALSE );
		$map->AddTBFloat(MapAttrAttr::$Y, 5, "Y",  FALSE ,  FALSE );
		$map->AddTBString(MapAttrAttr::$GUID, NULL, "GUID",  TRUE ,  FALSE , 0, 128, 20);
		$map->AddTBInt(MapAttrAttr::$EditType, 0, "编辑类型",  TRUE ,  FALSE );
		$map->AddTBString(MapAttrAttr::$Tag, NULL, "标识",  TRUE ,  FALSE , 0, 100, 20);
		$map->AddTBString(MapAttrAttr::$Tag1, NULL, "标识1",  TRUE ,  FALSE , 0, 100, 20);
		$map->AddTBString(MapAttrAttr::$Tag2, NULL, "标识2",  TRUE ,  FALSE , 0, 100, 20);
		$map->AddTBString(MapAttrAttr::$Tag3, NULL, "标识3",  TRUE ,  FALSE , 0, 100, 20);
		$map->AddTBString(MapAttrAttr::$Tip, NULL, "�?活提�?",  FALSE ,  TRUE , 0, 200, 20);
		$map->AddTBInt(MapAttrAttr::$ColSpan, 1, "单元格数�?",  TRUE ,  FALSE );
		$map->AddTBInt(MapAttrAttr::$TextColSpan, 1, "文本单元格数�?",  TRUE ,  FALSE );
		$map->AddTBInt(MapAttrAttr::$RowSpan, 1, "行数",  TRUE ,  FALSE );
		$map->AddTBInt(MapAttrAttr::$GroupID, 1, "显示的分�?",  TRUE ,  FALSE );
		$map->AddBoolean(MapAttrAttr::$IsEnableInAPP,  TRUE , "是否在移动端中显�?",  TRUE ,  TRUE );
		$map->AddTBInt(MapAttrAttr::$Idx, 0, "序号",  TRUE ,  FALSE );
		$map->AddTBAtParas(4000);
		$this->set_enMap($map);
		return $this->get_enMap();
	}
	protected function afterInsert () 
	{
		parent->afterInsert();
	}
	public function SaveBigNoteHtmlText ($text) // [String text]
	{
		$file = (((SystemConfig::getPathOfDataUser() . "/CCForm/BigNoteHtmlText/") . $this->getFK_MapData()) . ".htm");
		$folder = (new File($file))->getParent();
		if (((new File($folder))->isDirectory() ==  FALSE ))
		{
			(new File($folder))->mkdirs();
		}
		DataType->WriteFile($file, $text);
		return "保存成功�?";
	}
	public function ReadBigNoteHtmlText () 
	{
		$doc = "";
		$file = (((SystemConfig::getPathOfDataUser() . "/CCForm/BigNoteHtmlText/") . $this->getFK_MapData()) . ".htm");
		$folder = (new File($file))->getParent();
		if (((new File($folder))->isDirectory() !=  FALSE ))
		{
			if ((new File($file))->isFile())
			{
				$doc =DataType->ReadTextFile($file);
			}
		}
		return $doc;
	}
	public function DoDownTabIdx () 
	{
		$this->DoOrderDown(MapAttrAttr::$FK_MapData, $this->getFK_MapData(), MapAttrAttr::$Idx);
	}
	public function DoUpTabIdx () 
	{
		$this->DoOrderUp(MapAttrAttr::$FK_MapData, $this->getFK_MapData(), MapAttrAttr::$Idx);
	}
	public function DoUp () 
	{
		$this->DoOrderUp(MapAttrAttr::$GroupID, $String->valueOf($this->getGroupID()), MapAttrAttr::$UIVisible, "1", MapAttrAttr::$Idx);
		$attr = MapAttr::constructor__();
		$attr->setMyPK(($this->getFK_MapData() . "_Title"));
		if (($attr->RetrieveFromDBSources() == 1))
		{
			$attr->Update("Idx", -1);
		}
		return "执行成功";
	}
	public function GenerHisFKData () 
	{
		$sf = SFTable::constructor__String($this->getUIBindKey());
		return $BP->Tools->Json->ToJson($sf->GenerHisDataTable());
	}
	public function DoDown () 
	{
		$this->DoOrderDown(MapAttrAttr::$GroupID, $String->valueOf($this->getGroupID()), MapAttrAttr::$UIVisible, "1", MapAttrAttr::$Idx);
		$attr = MapAttr::constructor__();
		$attr->setMyPK(($this->getFK_MapData() . "_Title"));
		if (($attr->RetrieveFromDBSources() == 1))
		{
			$attr->Update("Idx", -1);
		}
		return "执行成功";
	}
	public function DoUpForMapDtl () 
	{
		$gf = GroupField::constructor__();
		$gf->Retrieve(GroupFieldAttr::$FrmID, $this->getFK_MapData());
		DBAccess::RunSQL((((("UPDATE Sys_MapAttr SET GroupID=" . $gf->getOID()) . " WHERE FK_MapData='") . $this->getFK_MapData()) . "'"));
		$this->DoOrderUp(MapAttrAttr::$FK_MapData, $this->getFK_MapData(), MapAttrAttr::$UIVisible, "1", MapAttrAttr::$Idx);
		$attr = MapAttr::constructor__();
		$attr->setMyPK(($this->getFK_MapData() . "_Title"));
		if (($attr->RetrieveFromDBSources() == 1))
		{
			$attr->Update("Idx", -1);
		}
		return "执行成功";
	}
	public function DoDownForMapDtl () 
	{
		$gf = GroupField::constructor__();
		$gf->Retrieve(GroupFieldAttr::$FrmID, $this->getFK_MapData());
		DBAccess::RunSQL((((("UPDATE Sys_MapAttr SET GroupID=" . $gf->getOID()) . " WHERE FK_MapData='") . $this->getFK_MapData()) . "'"));
		$this->DoOrderDown(MapAttrAttr::$FK_MapData, $this->getFK_MapData(), MapAttrAttr::$UIVisible, "1", MapAttrAttr::$Idx);
		$attr = MapAttr::constructor__();
		$attr->setMyPK(($this->getFK_MapData() . "_Title"));
		if (($attr->RetrieveFromDBSources() == 1))
		{
			$attr->Update("Idx", -1);
		}
		return "执行成功";
	}
	public function DoJump ($attrTo) // [MapAttr attrTo]
	{
		if (($attrTo->getIdx() <= $this->getIdx()))
		{
			$this->DoJumpUp($attrTo);
		}
		else
		{
			$this->DoJumpDown($attrTo);
		}
	}
	protected function DoJumpUp ($attrTo) // [MapAttr attrTo]
	{
		$sql = ((((("UPDATE Sys_MapAttr SET Idx=Idx+1 WHERE Idx <=" . $attrTo->getIdx()) . " AND FK_MapData='") . $this->getFK_MapData()) . "' AND GroupID=") . $this->getGroupID());
		DBAccess::RunSQL($sql);
		$this->setIdx(($attrTo->getIdx() - 1));
		$this->setGroupID($attrTo->getGroupID());
		$this->Update();
		return NULL;
	}
	protected function DoJumpDown ($attrTo) // [MapAttr attrTo]
	{
		$sql = ((((("UPDATE Sys_MapAttr SET Idx=Idx-1 WHERE Idx <=" . $attrTo->getIdx()) . " AND FK_MapData='") . $this->getFK_MapData()) . "' AND GroupID=") . $this->getGroupID());
		DBAccess::RunSQL($sql);
		$this->setIdx(($attrTo->getIdx() + 1));
		$this->setGroupID($attrTo->getGroupID());
		$this->Update();
		return NULL;
	}
	protected function beforeUpdateInsertAction () 
	{
		if ($String->valueOf($this->getGroupID())->equals("0"))
		{
			$group = GroupField::constructor__();
			if (($group->Retrieve(GroupFieldAttr::$FrmID, $this->getFK_MapData()) > 0))
			{
				$this->setGroupID($group->getOID());
			}
			else
			{
				$group->setFrmID($this->getFK_MapData());
				$group->setLab("基础信息");
				$group->setIdx(1);
				$group->Insert();
				$this->setGroupID($group->getOID());
			}
		}
		if ((($this->getLGType() == $FieldTypeS->Enum) && ($this->getUIContralType() == $UIContralType->RadioBtn)))
		{
			$sql = (((((("UPDATE Sys_FrmRB SET UIIsEnable=" . $this->GetValIntByKey(MapAttrAttr::$UIIsEnable)) . " WHERE FK_MapData='") . $this->getFK_MapData()) . "' AND KeyOfEn='") . $this->getKeyOfEn()) . "'");
			DBAccess::RunSQL($sql);
		}
		if (($this->getMyDataType() == $DataType->AppDate))
		{
			$this->setUIWidth(125);
		}
		if (($this->getMyDataType() == $DataType->AppDateTime))
		{
			$this->setUIWidth(145);
		}
		return parent->beforeUpdateInsertAction();
	}
	protected function beforeUpdate () 
	{
		switch ($this->getMyDataType()) {
			case $DataType->AppDateTime:
				$this->setMaxLen(20);
				break;
			case $DataType->AppDate:
				$this->setMaxLen(10);
				break;
			default:
				break;
		}
		if ($DataType->IsNullOrEmpty($this->getKeyOfEn()))
		{
			$this->setMyPK($this->getFK_MapData());
		}
		else
		{
			$this->setMyPK((($this->getFK_MapData() . "_") . $this->getKeyOfEn()));
		}
		return parent->beforeUpdate();
	}
	protected function beforeInsert () 
	{
		if ($DataType->IsNullOrEmpty($this->getName()))
		{
			throw new \RuntimeException("@请输入字段名称�??");
		}
		if ((($this->getKeyOfEn() . NULL) . $this->getKeyOfEn()->trim()->equals("")))
		{
			try 
			{
			/* match: String_b_b_I */
				$this->setKeyOfEn(CCFormAPI->ParseStringToPinyinField_String_b_b_I($this->getName(),  TRUE ,  TRUE , 100));
				if (($this->getKeyOfEn()->length() > 20))
				{
			/* match: String_b_b_I */
					$this->setKeyOfEn(CCFormAPI->ParseStringToPinyinField_String_b_b_I($this->getName(),  FALSE ,  TRUE , 20));
				}
				if ((($this->getKeyOfEn() . NULL) . $this->getKeyOfEn()->trim()->equals("")))
				{
					throw new \RuntimeException("@请输入字段描述或者字段名称�??");
				}
			}
			catch (\RuntimeException $ex)
			{
				throw new \RuntimeException(("@请输入字段描述或字段名称，异常信�?:" . $ex->getMessage()));
			}
		}
		else
		{
			$this->setKeyOfEn(PubClass::DealToFieldOrTableNames($this->getKeyOfEn()));
		}
		$tempVar = $this->getKeyOfEn();
		$keyofenC = ( ($tempVar instanceof String) ? $tempVar : NULL );
		$keyofenC = $keyofenC->toLowerCase();
		if ((PubClass::getKeyFields()->contains((("," . $keyofenC) . ",")) ==  TRUE ))
		{
			throw new \RuntimeException((("@错误:[" . $this->getKeyOfEn()) . "]是字段关键字，您不能用它做字段�??"));
		}
		if ($this->IsExit(MapAttrAttr::$KeyOfEn, $this->getKeyOfEn(), MapAttrAttr::$FK_MapData, $this->getFK_MapData()))
		{
			return  FALSE ;
		}
		if (($this->getIdx() == 0))
		{
			$this->setIdx((DBAccess->RunSQLReturnValInt($String->format((("SELECT %1$s FROM Sys_MapAttr WHERE FK_MapData='" . $this->getFK_MapData()) . "'"), $SqlBuilder->GetIsNullInSQL("MAX(Idx)", "0"))) + 1));
		}
		$this->setMyPK((($this->getFK_MapData() . "_") . $this->getKeyOfEn()));
		return parent->beforeInsert();
	}
	protected function beforeDelete () 
	{
		$sqls = (((((("DELETE FROM Sys_MapExt WHERE (AttrOfOper='" . $this->getKeyOfEn()) . "' OR AttrsOfActive='") . $this->getKeyOfEn()) . "' ) AND (FK_MapData='") . $this->getFK_MapData()) . "')");
		$sqls += (((("@DELETE FROM Sys_FrmSln WHERE KeyOfEn='" . $this->getKeyOfEn()) . "' AND FK_MapData='") . $this->getFK_MapData()) . "'");
		if ((($this->getUIContralType() == $UIContralType->DDL) && ($this->getLGType() == $FieldTypeS->Normal)))
		{
			$sqls += (((("@DELETE FROM Sys_MapAttr WHERE KeyOfEn='" . $this->getKeyOfEn()) . "T' AND FK_MapData='") . $this->getFK_MapData()) . "'");
		}
		DBAccess->RunSQLs($sqls);
		return parent->beforeDelete();
	}
}
?>
